/**
* <p>Title: RedisUitls.java</p>
* <p>Description: </p>
* <p>Company: www.huoyunren.com</p>
* @author duanxiangyun
* @date 2016年9月1日
* @version 1.0
*/
package com.hxbd.test.utils;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import redis.clients.jedis.Jedis;

public class Redis implements IRedis {
	Jedis jedis = null;
	public Redis (String ip, Integer port) {
		jedis = new Jedis(ip,port);  
	}
	
	@Override
	public void sadd(String key, Set<String> value) throws Exception {
		for(String str: value){
			jedis.sadd(key, str);
		}
//		Iterator<String> it = value.iterator();  
//		while (it.hasNext()) {  
//		 String str = it.next();
//		 System.out.println(str);
//		 jedis.sadd(key,str);  
//		}  

	}

	@Override
	public void set(String key, String value) throws Exception {
		jedis.set(key,value);
		
	}

	@Override
	public void srem(String key, Set<String> value) throws Exception {
		Iterator<String> it = value.iterator();
		while(it.hasNext()){
			String str = it.next();
			jedis.srem(key, str);
		}
	}

	@Override
	public String get(String key) throws Exception {
		return jedis.get(key);
	}

	@Override
	public Long scard(String key) throws Exception {
		return jedis.scard(key);
	}

	@Override
	public Set<String> smembers(String key) throws Exception {
		return jedis.smembers(key);
	}

	@Override
	public boolean sismember(String key, String value) throws Exception {
		return jedis.sismember(key,value);
	}

	@Override
	public String srandmember(String key) throws Exception {
		return jedis.srandmember(key);
	}

	@Override
	public void hmset(String key, Map<String, String> map) throws Exception {
		jedis.hmset(key,map);
	}

	@Override
	public Long hlen(String key) throws Exception {
		return jedis.hlen(key);
	}

	@Override
	public Set<String> hkeys(String key) throws Exception {
		return jedis.hkeys(key);
	}

	@Override
	public List<String> hvals(String key) throws Exception {
		return jedis.hvals(key);
	}

	@Override
	public List<String> hmget(String key, String s1, String s2)
			throws Exception {
		return jedis.hmget(key,s1,s2);
	}

	@Override
	public void hdel(String key, String s) throws Exception {
		jedis.hdel(key,s);
	}

	@Override
	public void lpush(String key, List<String> list) throws Exception {
		for(String s: list){
			jedis.lpush(key,s);
		}
	}

	@Override
	public List<String> lrange(String key, Long start, Long end)
			throws Exception {
		return jedis.lrange(key, start, end);
	}

	@Override
	public void del(String key) throws Exception {
		jedis.del(key);
	}

	@Override
	public void append(String key, String value) throws Exception {
		jedis.append(key,value);
	}
		
	public static void main(String[] args) {
		Redis r = new Redis("c4d826ca4a3c464f.redis.rds.aliyuncs.com",6739);  
        Set<String> set = new HashSet<String>();  
        set.add("w");  
        set.add("b");  
        try {
			r.sadd("zsss",set);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
        Set<String> t = null;
		try {
			t = r.smembers("zsss");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
        System.out.println(t);  
	}
}

